﻿using ConfExpert.Forms.Base;

using DevExpress.XtraEditors.Repository;
using DevTeam;

using System;
namespace ConfExpert.Forms.Depo.Aksesuar
{
    public partial class SayimAnaliz3 : XForm
    {
        public SayimAnaliz3()
        {
            InitializeComponent();
        }

        private void SayimAnaliz3_Load(object sender, EventArgs e)
        {
            
            gvAksSayim.Init("GetAksSayimAnaliz3", 0);

            gvAksSayim.FormatAsDate("Gun");
            //gvAksSayim.FormatAsPercentage("DuzeltmeOrani");
            gvAksSayim.FormatAsNumber(0, "OGunkuMiktar", "SayimEksigi", "SayimFazlasi");
            gvAksSayim.AddSummary("OGunkuMiktar", "SayimEksigi", "SayimFazlasi");
            gvAksSayim.YanYanaGetirSoluna("BrandId", "SayimFazlasi", "SayimEksigi", "OGunkuMiktar", "DuzeltmeOrani");
            gvAksSayim.MakeReadOnly();
            gvAksSayim.BestFitColumns();

            //txtInfo.Caption = "Completion: %" + gvAksSayim.DataTable().Rows.Count / 78.61;

            GridManager gm = GridManager.GetManager(gvAksSayim);
            gm.GridMenu.AddMenu("Stok Hareketleri", StokHareketleri);

            gleBrand.Edit.Assign(RI(Rp.Brand));
            ((RepositoryItemGridLookUpEdit)gleBrand.Edit).TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
            gleBrand.EditValueChanged += gleBrand_EditValueChanged;
        }

        void gleBrand_EditValueChanged(object sender, EventArgs e)
        {
            bbiGuncelle.PerformClick();
        }

        void StokHareketleri(object sender, EventArgs e)
        {
            int handle = gvAksSayim.FocusedRowHandle;

            if (handle > -1)
            {
                int AksesuarId = intParse(gvAksSayim.GetRowCellValue(handle, "AksesuarId"));
                using (AksesuarHareketGC ah = new AksesuarHareketGC(AksesuarId, null, null))
                    ah.ShowDialog();
            }
        }

        private void bbiGuncelle_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gvAksSayim.RefreshDataSource(true, "GetAksSayimAnaliz3", intParse(gleBrand.EditValue));
            gvAksSayim.BestFitColumns();
        }
    }
}
